//
//  ZPMacros.h
//  ZPIOSEducation
//
//  Created by mini1 on 2016/12/5.
//  Copyright © 2016年 mini1. All rights reserved.
//

#ifndef ZPMacros_h
#define ZPMacros_h

//** 沙盒路径 ***********************************************************************************
#define PATH_OF_APP_HOME    NSHomeDirectory()
#define PATH_OF_TEMP        NSTemporaryDirectory()
#define PATH_OF_DOCUMENT    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]


/* ****************************************************************************************************************** */
/** DEBUG LOG **/
//#ifdef DEBUG
//
//#define DLog(FORMAT, ... ) NSLog( @"< %@:(%d) > %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
//
//#else
//
//#define DLog(FORMAT, ... )
//
//#endif


//**打印日志************************************************************************************************** */
/** DEBUG LOG **/
#ifdef DEBUG

#define ZPLog(FORMAT, ...) fprintf(stderr, "%s [%d lines] %s\n", __PRETTY_FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define ZPLog(FORMAT, ...) nil

#endif




/** DEBUG RELEASE **/
#if DEBUG

#define MCRelease(x)            [x release]

#else

#define MCRelease(x)            [x release], x = nil

#endif


/** NIL RELEASE **/
#define NILRelease(x)           [x release], x = nil


/* ****************************************************************************************************************** */
#pragma mark - Frame (宏 x, y, width, height)

// App Frame
#define Application_Frame       [[UIScreen mainScreen] applicationFrame]

// App Frame Height&Width
#define App_Frame_Height        [[UIScreen mainScreen] applicationFrame].size.height
#define App_Frame_Width         [[UIScreen mainScreen] applicationFrame].size.width

// MainScreen Height&Width&Window
#define Main_Screen_Height      [[UIScreen mainScreen] bounds].size.height
#define Main_Screen_Width       [[UIScreen mainScreen] bounds].size.width
#define Main_Screen_Bounds      [UIScreen mainScreen].bounds
#define K_WINDOW [[UIApplication sharedApplication] keyWindow]
#define T_VIEW     [[UIApplication sharedApplication] keyWindow].rootViewController.view


#define zDelay  1.5
#define delayRun dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kDelay * NSEC_PER_SEC)), dispatch_get_main_queue()

#define zDelay01  0.7
#define delayRun05 dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kDelay01 * NSEC_PER_SEC)), dispatch_get_main_queue()

#define zFileManager [NSFileManager defaultManager]
#define zUserDefaults   [NSUserDefaults standardUserDefaults]
#define zWindow         [[UIApplication sharedApplication] keyWindow]
#define func  NSLog(@"current - %s",__func__)

// View 坐标(x,y)和宽高(width,height)
#define X(v)                    (v).frame.origin.x
#define Y(v)                    (v).frame.origin.y
#define WIDTH(v)                (v).frame.size.width
#define HEIGHT(v)               (v).frame.size.height

#define CENTER_X(v)             (v).center.x
#define CENTER_Y(v)             (v).center.y

#define MinX(v)                 CGRectGetMinX((v).frame)
#define MinY(v)                 CGRectGetMinY((v).frame)

#define MidX(v)                 CGRectGetMidX((v).frame)
#define MidY(v)                 CGRectGetMidY((v).frame)

#define MaxX(v)                 CGRectGetMaxX((v).frame)
#define MaxY(v)                 CGRectGetMaxY((v).frame)


#define RECT_CHANGE_x(v,x)          CGRectMake(x, Y(v), WIDTH(v), HEIGHT(v))
#define RECT_CHANGE_y(v,y)          CGRectMake(X(v), y, WIDTH(v), HEIGHT(v))
#define RECT_CHANGE_point(v,x,y)    CGRectMake(x, y, WIDTH(v), HEIGHT(v))
#define RECT_CHANGE_width(v,w)      CGRectMake(X(v), Y(v), w, HEIGHT(v))
#define RECT_CHANGE_height(v,h)     CGRectMake(X(v), Y(v), WIDTH(v), h)
#define RECT_CHANGE_size(v,w,h)     CGRectMake(X(v), Y(v), w, h) 

/// 系统控件默认高度
#define zStatusBarHeight        (20.f)

#define zTopBarHeight           (44.f)
#define zBottomBarHeight        (49.f)

#define zCellDefaultHeight      (44.f)

#define zEnglishKeyboardHeight  (216.f)
#define zChineseKeyboardHeight  (252.f)

/// 表格组间距
#define zTableViewGroupSpacing_8 8
#define zTableViewGroupSpacing_0 0.01


/* ****************************************************************************************************************** */
#pragma mark - Funtion Method (宏 方法)

// PNG JPG 图片路径
#define PNGPATH(NAME)           [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"png"]
#define JPGPATH(NAME)           [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"jpg"]
#define PATH(NAME, EXT)         [[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]

// 加载图片
#define PNGkImg(NAME)          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"png"]]
#define JPGkImg(NAME)          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"jpg"]]
#define kImg(NAME, EXT)        [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]]

#define Z_IMAGE(imgName) [UIImage imageNamed:imgName]


#define URL(url) [NSURL URLWithString:url]
#define string(str1,str2) [NSString stringWithFormat:@"%@%@",str1,str2]
#define s_str(str1) [NSString stringWithFormat:@"%@",str1]
#define s_Num(num1) [NSString stringWithFormat:@"%d",num1]
#define s_Integer(num1) [NSString stringWithFormat:@"%ld",num1]

// 字体大小(常规/粗体)
#define BOLDSYSTEMFONT(FONTSIZE)[UIFont boldSystemFontOfSize:FONTSIZE]
#define SYSTEMFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE]
#define FONT(NAME, FONTSIZE)    [UIFont fontWithName:(NAME) size:(FONTSIZE)]

// 微软雅黑
#define YC_YAHEI_FONT(FONTSIZE) [UIFont fontWithName:@"MicrosoftYaHei" size:(FONTSIZE)]
// 英文 和 数字
#define YC_ENGLISH_FONT(FONTSIZE) [UIFont fontWithName:@"Helvetica Light" size:(FONTSIZE)]

// 颜色(RGB)
#define RGBCOLOR(r, g, b)       [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r, g, b, a)   [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

//number转String
#define IntTranslateStr(int_str) [NSString stringWithFormat:@"%d",int_str];
#define FloatTranslateStr(float_str) [NSString stringWithFormat:@"%.2d",float_str];

// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

// 由角度获取弧度
#define ZPDegreesToRadian(x) (M_PI * (x) / 180.0)
// 由弧度获取角度
#define ZPRadianToDegrees(radian) (radian * 180.0) / (M_PI)


// 当前版本
#define FSystemVersion          ([[[UIDevice currentDevice] systemVersion] floatValue])
#define DSystemVersion          ([[[UIDevice currentDevice] systemVersion] doubleValue])
#define SSystemVersion          ([[UIDevice currentDevice] systemVersion])

// 当前语言
#define CURRENTLANGUAGE         ([[NSLocale preferredLanguages] objectAtIndex:0])

// 是否Retina屏
#define isRetina                ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
CGSizeEqualToSize(CGSizeMake(640, 960), \
[[UIScreen mainScreen] currentMode].size) : \
NO)

// 是否iPhone4
#define isiPhone4               ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
CGSizeEqualToSize(CGSizeMake(640, 960), \
[[UIScreen mainScreen] currentMode].size) : \
NO)

// 是否iPhone5
#define isiPhone5               ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
CGSizeEqualToSize(CGSizeMake(640, 1136), \
[[UIScreen mainScreen] currentMode].size) : \
NO)

// 是否iPhone6
#define isiPhone6              ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
CGSizeEqualToSize(CGSizeMake(750, 1334), \
[[UIScreen mainScreen] currentMode].size) : \
NO)

// 是否iPhone6plus
#define isiPhone6_Plus              ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
CGSizeEqualToSize(CGSizeMake(1242, 2208), \
[[UIScreen mainScreen] currentMode].size) : \
NO)


// 是否IOS7
#define isIOS7                  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
// 是否IOS6
#define isIOS6                  ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)

// 是否iPad
#define isPad                   (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

// UIView - viewWithTag
#define VIEWWITHTAG(_OBJECT, _TAG)\
\
[_OBJECT viewWithTag : _TAG]

// 本地化字符串
/** NSLocalizedString宏做的其实就是在当前bundle中查找资源文件名“Localizable.strings”(参数:键＋注释) */
#define LocalString(x, ...)     NSLocalizedString(x, nil)
/** NSLocalizedStringFromTable宏做的其实就是在当前bundle中查找资源文件名“xxx.strings”(参数:键＋文件名＋注释) */
#define AppLocalString(x, ...)  NSLocalizedStringFromTable(x, @"someName", nil)

// RGB颜色转换（16进制->10进制）
#define UIColorFromRGB(rgbValue)\
\
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 \
alpha:1.0]

#if TARGET_OS_IPHONE
/** iPhone Device */
#endif

#if TARGET_IPHONE_SIMULATOR
/** iPhone Simulator */
#endif

// ARC
#if __has_feature(objc_arc)
/** Compiling with ARC */
#else
/** Compiling without ARC */
#endif

#define PushVC(A_VC) \
A_VC *vc = [[A_VC alloc]init];\
[self.navigationController pushViewController:vc animated:YES];
/* ****************************************************************************************************************** */
#pragma mark - Log Method (宏 LOG)

// 日志 / 断点
// =============================================================================================================================
// DEBUG模式
#define ITTDEBUG

// LOG等级
#define ITTLOGLEVEL_INFO        10
#define ITTLOGLEVEL_WARNING     3
#define ITTLOGLEVEL_ERROR       1

// =============================================================================================================================
// LOG最高等级
#ifndef ITTMAXLOGLEVEL

#ifdef DEBUG
#define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO
#else
#define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR
#endif

#endif

// =============================================================================================================================
// LOG PRINT
// The general purpose logger. This ignores logging levels.
#ifdef ITTDEBUG
#define ITTDPRINT(xx, ...)      NSLog(@"< %s:(%d) > : " xx , __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define ITTDPRINT(xx, ...)      ((void)0)
#endif

// Prints the current method's name.
#define ITTDPRINTMETHODNAME()   ITTDPRINT(@"%s", __PRETTY_FUNCTION__)

// Log-level based logging macros.
#if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL
#define ITTDERROR(xx, ...)      ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDERROR(xx, ...)      ((void)0)
#endif

#if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL
#define ITTDWARNING(xx, ...)    ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDWARNING(xx, ...)    ((void)0)
#endif

#if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL
#define ITTDINFO(xx, ...)       ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDINFO(xx, ...)       ((void)0)
#endif

// 条件LOG
#ifdef ITTDEBUG
#define ITTDCONDITIONLOG(condition, xx, ...)\
\
{\
if ((condition))\
{\
ITTDPRINT(xx, ##__VA_ARGS__);\
}\
}
#else
#define ITTDCONDITIONLOG(condition, xx, ...)\
\
((void)0)
#endif

// 断点Assert
#define ITTAssert(condition, ...)\
\
do {\
if (!(condition))\
{\
[[NSAssertionHandler currentHandler]\
handleFailureInFunction:[NSString stringWithFormat:@"< %s >", __PRETTY_FUNCTION__]\
file:[[NSString stringWithUTF8String:__FILE__] lastPathComponent]\
lineNumber:__LINE__\
description:__VA_ARGS__];\
}\
} while(0)
/* ************************************************************************************************* */
///正常字体
#define UISystemFontSize(CGFloat) [UIFont systemFontOfSize:CGFloat]
#define Z30 [UIFont systemFontOfSize:30]
#define Z29 [UIFont systemFontOfSize:29]
#define Z28 [UIFont systemFontOfSize:28]
#define Z27 [UIFont systemFontOfSize:27]
#define Z26 [UIFont systemFontOfSize:26]
#define Z25 [UIFont systemFontOfSize:25]
#define Z24 [UIFont systemFontOfSize:24]
#define Z23 [UIFont systemFontOfSize:23]
#define Z22 [UIFont systemFontOfSize:22]
#define Z20 [UIFont systemFontOfSize:20]
#define Z19 [UIFont systemFontOfSize:19]
#define Z18 [UIFont systemFontOfSize:18]
#define Z17 [UIFont systemFontOfSize:17]
#define Z16 [UIFont systemFontOfSize:16]
#define Z15 [UIFont systemFontOfSize:15]
#define Z14 [UIFont systemFontOfSize:14]
#define Z13 [UIFont systemFontOfSize:13]
#define Z12 [UIFont systemFontOfSize:12]
#define Z11 [UIFont systemFontOfSize:11]
#define Z10 [UIFont systemFontOfSize:10]
#define Z9  [UIFont systemFontOfSize:9]
#define Z8  [UIFont systemFontOfSize:8]

///粗体
#define UIBoldSystemFontSize(CGFloat) [UIFont boldSystemFontOfSize:CGFloat]
#define ZB20 [UIFont boldSystemFontOfSize:20]
#define ZB18 [UIFont boldSystemFontOfSize:18]
#define ZB16 [UIFont boldSystemFontOfSize:16]
#define ZB14 [UIFont boldSystemFontOfSize:14]
#define ZB13 [UIFont boldSystemFontOfSize:13]
#define ZB12 [UIFont boldSystemFontOfSize:12]
#define ZB11 [UIFont boldSystemFontOfSize:11]
#define ZB10 [UIFont boldSystemFontOfSize:10]
#define ZB9  [UIFont boldSystemFontOfSize:9]
#define ZB8  [UIFont boldSystemFontOfSize:8]

///斜体
#define UIItalicSystemFontSize(CGFloat) [UIFont italicSystemFontOfSize:CGFloat]

/* ************************************************************************************************* */

///常用颜色
#define black_color     [UIColor blackColor]
#define blue_color      [UIColor blueColor]
#define brown_color     [UIColor brownColor]
#define clear_color     [UIColor clearColor]
#define darkGray_color  [UIColor darkGrayColor]
#define darkText_color  [UIColor darkTextColor]
#define white_color     [UIColor whiteColor]
#define yellow_color    [UIColor yellowColor]
#define red_color       [UIColor redColor]
#define orange_color    [UIColor orangeColor]
#define purple_color    [UIColor purpleColor]
#define cyan_color      [UIColor cyanColor]
#define lightText_color [UIColor lightTextColor]
#define lightGray_color [UIColor lightGrayColor]
#define green_color     [UIColor greenColor]
#define gray_color      [UIColor grayColor]
#define magenta_color   [UIColor magentaColor]
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)
#define kBackColor UIColorFromRGB(0xd81460)

// 自定义颜色
#define zFreeColor(R,G,B,A) [UIColor colorWithRed:(R)/255.0 green:(G)/255.0 blue:(B)/255.0 alpha:(A)]
// 石头培优主色调
#define zMainColor [UIColor colorWithRed:33/255.0 green:164/255.0 blue:235/255.0 alpha:1.0]
#define zColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
// 随机色
#define zRandomColor zColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
// 新特性开始体验文字颜色
#define zStartButtonTextColor [UIColor colorWithRed:241/255.0 green:184/255.0 blue:92/255.0 alpha:1]
// 通用灰色线颜色
#define zLineLightGrayColor [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1]
// 注册登录界面控件和字体背景颜色
#define zPhonePasswordLabelTextColor [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.6]
#define zPhonePasswordTextLineColor [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.6]
#define zLoginButtonBackgroundColor [UIColor colorWithRed:255/255.0 green:86/255.0 blue:86/255.0 alpha:1]
// 验证码背景色
#define zVerificationBackgroundColor [UIColor colorWithRed:13/255.0 green:113/255.0 blue:162/255.0 alpha:1]
// 注册登录底部Btn红色背景色
#define zNextBtnBackgroundColor [UIColor colorWithRed:13/255.0 green:113/255.0 blue:162/255.0 alpha:0.4]
// rgb颜色转换（16进制->10进制
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]


/* ************************************************************************************************* */

//系统版本号
#define _DEVICE_SYSTEM_VERSION_  [[[UIDevice currentDevice] systemVersion]floatValue]
#define CurrentSystemVersion [UIDevice currentDevice] systemVersion]

///设备的UDID号
//#define UDID [[[UIDevice currentDevice] identifierForVendor] UUIDString]
#define CodeIs200(x) ([NSString stringWithFormat:@"%@",[x objectForKey:@"code"]].intValue==200)
//屏幕高、宽
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height - 64

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#define VersionLargerThan7  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define VersionLargerThan8  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

#define Version7  ([[[UIDevice currentDevice] systemVersion] floatValue] == 7.0)
#define Version8  ([[[UIDevice currentDevice] systemVersion] floatValue] == 8.0)

///获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

///获取iphone机型
#define is35InchScreen() ([UIScreen mainScreen].bounds.size.height == 480)

#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750,1334), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone6_Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2208), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define NU(x) (x?x:@"")
//1.iPhone4分辨率320x480，像素640x960，@2x
//2.iPhone5分辨率320x568，像素640x1136，@2x
//3.iPhone6分辨率375x667，像素750x1334，@2x
//4.iPhone6 Plus分辨率414x736，像素1242x2208，@3x

///获取Xcode的版本号
#define XcodeAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]



/* ****************************************************************************************************************** */
#pragma mark - Constants (宏 常量)


/** 时间间隔 */
#define kHUDDuration            (1.f)

/** 一天的秒数 */
#define SecondsOfDay            (24.f * 60.f * 60.f)

/** 秒数 x 天数 */
#define Seconds(Days)           (24.f * 60.f * 60.f * (Days))

/** 一天的毫秒数 */
#define MillisecondsOfDay       (24.f * 60.f * 60.f * 1000.f)

/** 毫秒数 x 天数 */
#define Milliseconds(Days)      (24.f * 60.f * 60.f * 1000.f * (Days))
#define toStr(Obj) (Obj)?[NSString stringWithFormat:@"%@",Obj]:@""

//** textAlignment ***********************************************************************************

#if !defined __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
# define LINE_BREAK_WORD_WRAP UILineBreakModeWordWrap
# define TextAlignmentLeft UITextAlignmentLeft
# define TextAlignmentCenter UITextAlignmentCenter
# define TextAlignmentRight UITextAlignmentRight
#else
# define LINE_BREAK_WORD_WRAP NSLineBreakByWordWrapping
# define TextAlignmentLeft NSTextAlignmentLeft
# define TextAlignmentCenter NSTextAlignmentCenter
# define TextAlignmentRight NSTextAlignmentRight
#endif

#endif /* ZPMacros_h */
